// Copyright (C) 2009 Jesse Jones
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
// 
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

using System;

internal abstract class Shape
{
}

internal sealed class Square : Shape
{
	public static int CallCount {get; private set;}
	
	[Union5.Overload]
	public Square Union(Square rhs)
	{
		++CallCount;
		return rhs;
	}
}

internal sealed class Disk : Shape
{
	public static int CallCount {get; private set;}
	
	[Union5.Overload]
	public static Disk Union(Disk lhs, Disk rhs)
	{
		++CallCount;
		return rhs;
	}
}

internal static class Program
{
	public static void Main(string[] args)
	{
		var s1 = new Square();
		var s2 = new Square();
		Union5.Invoke(s1, s2);
		if (Square.CallCount != 1) throw new Exception("error1");
		if (Disk.CallCount != 0) throw new Exception("error2");
		
		Shape d1 = new Disk();
		Shape d2 = new Disk();
		Union5.Invoke(d1, d2);
		if (Square.CallCount != 1) throw new Exception("error3");
		if (Disk.CallCount != 1) throw new Exception("error4");
	}
}
